﻿/****************************** Module Header ******************************\
 * Module Name:  JCountDown.cs
 * Module Version:  2.0.0 (2012-10-18)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This componse is use for JCountDown.
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace UCF.Core.Web.CustomControls
{
    /// <summary>
    /// 倒计时插件
    /// </summary>
    /// <example>
    /// <![CDATA[
    /// <so:JCountDown runat="server" ID="aa" Year="2013" />
    /// ]]>
    /// </example>
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:JCountDown runat=server></{0}:JCountDown>")]
    public class JCountDown : HtmlContainerControl
    {
        public int Year { get; set; }
        public int Month { get; set; }
        public int Day { get; set; }
        public int Hour { get; set; }
        public int Minute { get; set; }
        public int Second { get; set; }
        protected override void OnPreRender(EventArgs e)
        {
            Page.PreRenderComplete+=new EventHandler(Page_PreRenderComplete);
            base.OnPreRender(e);
        }
        private void Page_PreRenderComplete(object s, EventArgs e)
        {
            Page.RegisterHeaderLink("css-jqcountdown", "/DMS/Skin/Js/JqPlus/JqCountDown/lwtCountdown/1.0/style/main.css");
            Page.ClientScript.RegisterClientScriptInclude("jqcountdown", "/DMS/Skin/Js/JqPlus/JqCountDown/lwtCountdown/1.0/js/jquery.lwtCountdown-1.0.js");
            Page.ClientScript.RegisterStartupScript(typeof(Page), this.UniqueID, string.Format("jQuery(document).ready(function(){{$('#{0}').countDown({{targetDate:{{'day':{1},'month':{2},'year':{3},'hour':{4},'min':{5},'sec':{6}}}}})}});",this.UniqueID,this.Day,this.Month,this.Year,this.Hour,this.Minute,this.Second),true);
        }
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write(string.Format("<div id='{0}'><div class='dash weeks_dash'><span class='dash_title'>weeks</span><div class='digit'>0</div><div class='digit'>0</div></div><div class='dash days_dash'><span class='dash_title'>days</span><div class='digit'>0</div><div class='digit'>0</div></div><div class='dash hours_dash'><span class='dash_title'>hours</span><div class='digit'>0</div><div class='digit'>0</div></div><div class='dash minutes_dash'><span class='dash_title'>minutes</span><div class='digit'>0</div><div class='digit'>0</div></div><div class='dash seconds_dash'><span class='dash_title'>seconds</span><div class='digit'>0</div><div class='digit'>0</div></div></div>",this.UniqueID));
        }
    }
}
